package com.zrrd.gmall.product.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zrrd.gmall.common.result.Result;
import com.zrrd.gmall.model.product.SpuInfo;
import com.zrrd.gmall.product.service.SpuInfoService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
public class SpuInfoController {

    @Autowired
    private SpuInfoService spuInfoService;

    //分页查询Spu
    @GetMapping("/{page}/{limit}")
    public Result<Page> page(@PathVariable("page") Integer page,
                             @PathVariable("limit") Integer size,
                             Long category3Id){
        //创建分页对象
        Page<SpuInfo> pageInfo = new Page<>(page,size);
        QueryWrapper<SpuInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("category3_id", category3Id);
        wrapper.orderByDesc("id");
        //执行分页查询
        spuInfoService.page(pageInfo,wrapper);
        //返回
        return Result.ok(pageInfo);
    }

    //查询基本销售属性列表(添加Spu时选择销售属性)
    @GetMapping("/baseSaleAttrList")
    public Result<List> baseSaleAttrList(){
        return Result.ok(spuInfoService.getBaseSaleAttrList());
    }

    //添加Spu
    @PostMapping("/saveSpuInfo")
    public Result<String> saveSpuInfo(@RequestBody SpuInfo spuInfo){
        spuInfoService.saveSupInfo(spuInfo);
        return Result.ok("成功");
    }
}
